cmake_minimum_required(VERSION 3.16)

project(demo VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Sql Network OpenGL Svg)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Sql Network OpenGL Svg)

set(PROJECT_SOURCES
        MapWidget.h
        UAS_types.h
        MapWidget_TestWindow.h
        MapWidget.cpp
        UAS_types.cpp
        MapWidget_TestWindow.cpp
        opmapcontrol_demo.cpp
        mapwidget/mapresources.qrc
        opmapcontrol.h
        core/accessmode.h
        core/alllayersoftype.h
        core/cache.h
        core/cacheitemqueue.h
        core/debugheader.h
        core/diagnostics.h
        core/geodecoderstatus.h
        core/kibertilecache.h
        core/languagetype.h
        core/maptype.h
        core/memorycache.h
        core/opmaps.h
        core/placemark.h
        core/point.h
        core/providerstrings.h
        core/pureimage.h
        core/pureimagecache.h
        core/rawtile.h
        core/size.h
        core/tilecachequeue.h
        core/urlfactory.h
        internals/copyrightstrings.h
        internals/core.h
        internals/debugheader.h
        internals/loadtask.h
        internals/mousewheelzoomtype.h
        internals/pointlatlng.h
        internals/pureprojection.h
        internals/rectangle.h
        internals/rectlatlng.h
        internals/sizelatlng.h
        internals/tile.h
        internals/tilematrix.h
        mapwidget/gpsitem.h
        mapwidget/homeitem.h
        mapwidget/mapgraphicitem.h
        mapwidget/mapripform.h
        mapwidget/mapripper.h
        mapwidget/opmapwidget.h
        mapwidget/trailitem.h
        mapwidget/traillineitem.h
        mapwidget/uavitem.h
        mapwidget/uavmapfollowtype.h
        mapwidget/uavtrailtype.h
        mapwidget/waypointitem.h
        mapwidget/waypointlineitem.h
        internals/projections/lks94projection.h
        internals/projections/mercatorprojection.h
        internals/projections/mercatorprojectionyandex.h
        internals/projections/platecarreeprojection.h
        internals/projections/platecarreeprojectionpergo.h
        core/alllayersoftype.cpp
        core/cache.cpp
        core/cacheitemqueue.cpp
        core/diagnostics.cpp
        core/kibertilecache.cpp
        core/languagetype.cpp
        core/memorycache.cpp
        core/opmaps.cpp
        core/placemark.cpp
        core/point.cpp
        core/providerstrings.cpp
        core/pureimage.cpp
        core/pureimagecache.cpp
        core/rawtile.cpp
        core/size.cpp
        core/tilecachequeue.cpp
        core/urlfactory.cpp
        internals/core.cpp
        internals/loadtask.cpp
        internals/MouseWheelZoomType.cpp
        internals/pointlatlng.cpp
        internals/pureprojection.cpp
        internals/rectangle.cpp
        internals/rectlatlng.cpp
        internals/sizelatlng.cpp
        internals/tile.cpp
        internals/tilematrix.cpp
        mapwidget/configuration.cpp
        mapwidget/gpsitem.cpp
        mapwidget/homeitem.cpp
        mapwidget/mapgraphicitem.cpp
        mapwidget/mapripform.cpp
        mapwidget/mapripper.cpp
        mapwidget/opmapwidget.cpp
        mapwidget/trailitem.cpp
        mapwidget/traillineitem.cpp
        mapwidget/uavitem.cpp
        mapwidget/waypointitem.cpp
        mapwidget/waypointlineitem.cpp
        internals/projections/lks94projection.cpp
        internals/projections/mercatorprojection.cpp
        internals/projections/mercatorprojectionyandex.cpp
        internals/projections/platecarreeprojection.cpp
        internals/projections/platecarreeprojectionpergo.cpp
        mapwidget/mapripform.ui
        mapwidget/mapresources.qrc
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(demo
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET demo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(demo SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(demo
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_include_directories(demo
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}/mapwidget
)


target_link_libraries(demo PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Sql Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::OpenGL
Qt${QT_VERSION_MAJOR}::Svg
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.demo)
endif()
set_target_properties(demo PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS demo
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(demo)
endif()
